package com.example.controller;

import com.example.bean.ApiResult;
import com.example.bean.Statement;
import com.example.service.StatementService;
import com.example.utils.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/statement")
@CrossOrigin
public class StatementController {

    @Autowired
    private StatementService statementService;

    @GetMapping("/profit")
    public ApiResult selectStatement() {
        List<Statement> res = statementService.selectStatement();
        if (res != null) return ApiResultHandler.buildApiResult(200, "查看办卡盈利的金额", res);
        return ApiResultHandler.buildApiResult(400, "无数据", res);
    }

    @PostMapping("/insert")
    public ApiResult selectStatement(@RequestBody Statement statement) {
        int res = statementService.insert(statement);
        if (res != 0) return ApiResultHandler.buildApiResult(200, "新增财务单成功", res);
        return ApiResultHandler.buildApiResult(400, "新增财务单失败", res);
    }

    @GetMapping("/fine")
    public ApiResult selectFine() {
        List<Statement> res = statementService.selectFine();
        if (res != null) return ApiResultHandler.buildApiResult(200, "查看罚款所受金额", res);
        return ApiResultHandler.buildApiResult(400, "无数据", res);
    }

    /*@GetMapping("/total")
    public ApiResult selectAll() {
        Statement res = statementService.selectAll();
        if (res != null) return ApiResultHandler.buildApiResult(200, "显示所有金额之和", res);
        return ApiResultHandler.buildApiResult(400, "无数据", res);
    }*/
}
